/**
 * 
 */
package com.zhaoyan.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bot.utils.NumberUtil;
import com.github.pagehelper.PageInfo;
import com.zhaoyan.pojo.VoteItem;
import com.zhaoyan.pojo.VoteTopic;
import com.zhaoyan.service.VoteService;

/**
 * @author zhaoyan
 *
 * 2020年1月30日
 */
@Controller
public class VoteController {
	
	@Autowired
	private VoteService voteService;
	
	
	@RequestMapping("showAll")
	public String showAll(Model m,@RequestParam(defaultValue = "1") Integer pageNum) {
		  
		PageInfo<VoteTopic> topicPage = voteService.showTopic(pageNum);
		
		m.addAttribute("topicPage", topicPage);
		
		return "show";
	}
	
	@RequestMapping("toUpdateVote")
	public String toAddVote(Integer id,Model m) {
		
		VoteTopic voteTopic = voteService.findQuestion(id);
		
		m.addAttribute("voteTopic", voteTopic);
		
		return "update";
	}
	
	@RequestMapping("showCount")
	@ResponseBody
	public Integer showCount(Integer id,Integer tid) {
		
		return voteService.showCount(id,tid);
	}

	@RequestMapping("updateVote")
	@ResponseBody
	public Integer updateVote(VoteItem item) {
		
		
		return voteService.updateOne(item);
		
	}
	
	
	//	异步的方式展示数据，但是有问题
//	@RequestMapping("showPercent")
//	@ResponseBody
//	public String showPercent(Integer currentNum,Integer totalNum) {
//		
//		System.out.println(currentNum);
//		
//		System.err.println(totalNum);
//		
//		int percent = NumberUtil.getPercent(currentNum, totalNum);
//		
//		System.out.println("百分比是："+percent);
//		
//		String msg = "<div class=\"progress\">\r\n" + 
//				"<div class=\"progress-bar\" role=\"progressbar\" style=\'width:"+percent+"% ;\' aria-valuenow=\"25\" aria-valuemin=\"0\" aria-valuemax=\"100\">"+percent+"%</div>\r\n" + 
//				"</div>";
//		
//		return msg;
//		
//	}
	
	
	
	
	
}
